#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys

sys.path.append(
    os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "imlfapi")
)

from db import EntityTB, WindFarmInfoTB


def main():
    # 查出所有entity
    entity_lst = EntityTB.find()
    # 循环所有entity
    for num, entity in enumerate(entity_lst):
        print("%s / %s" % (num, len(entity_lst)))
        # 在windfarminfo表中查出entity类型
        wind_farm_info = WindFarmInfoTB.find_one(wfid=entity["biz_id"])
        # 更新entity的f_type字段
        if wind_farm_info:
            EntityTB.set(f_type=wind_farm_info["f_type"]).where(id=entity["id"])
            print("success:%s" % entity["id"])


if __name__ == "__main__":
    main()
